import { onMounted, onUnmounted, ref } from "vue";


// 自定义 hook 函数
export default function(){
  const x = ref(-1)
  const y = ref(-1)
  
  const handler = (event: MouseEvent) => {
    x.value = event.pageX
    y.value = event.pageY
  }

  // 页面加载添加鼠标事件
  onMounted(()=> {
     window.addEventListener('click',  handler)
  })
  onUnmounted(()=> {
    window.removeEventListener('click', handler)
  })

  return {
    x, y
  }

}
